<extend name="Public:base"/>

<!--侧边导航-->
<block name="aside">
    <include file="Public:aside"/>
</block>

<block name="main">

<div class="row">
    <div class="col-md-12">
        <form id="myform" name="myform" class="form-horizontal" action="{:U('Category/add')}" method="post">

            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active"><a href="#home" role="tab" data-toggle="tab">基本设置</a></li>
                <li role="presentation"><a href="#profile" role="tab" data-toggle="tab">SEO设置</a></li>
                <!--<li><a href="#extend" role="tab" data-toggle="tab">扩展信息</a></li>-->
            </ul>

            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="home">
                    <div class="form-group">
                        <label class="control-label col-md-2">上级栏目</label>
                        <div class="col-md-8">
                            <div class="selectstyle">
                                <select name="parentid" class="form-control">
                                    <option value="">{:L('select_parentid')}</option>
                                    {$select_categorys}
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="form-group" <?php if($_SESSION['admin']['role'] != 1):?>style="display:none;"<?php endif;?>>
                        <label class="control-label col-md-2">栏目类型</label>
                        <div class="col-md-8">
                            <div class="selectstyle">
                                {:Form::select(
                                array('field'=>'modelid',
                                'options'=>$model+array('0'=>array('id'=>0,'name'=>'外部链接')),
                                'options_key'=>'id,name',
                                'setup'=>array('onchange'=>'changetemplate(this.value)')),
                                $vo['modelid']
                                )}
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-2">栏目名称</label>
                        <div class="col-md-8">
                            <input type="text" name="catname" id="catname" class="form-control  required" value="{$vo['catname']}"  minlength="1" />
                        </div>
                    </div>
                    <?php if($_SESSION['admin']['role'] == 1):?>
                    <div class="form-group">
                        <label class="control-label col-md-2">页面命名</label>
                        <div class="col-md-8">
                            <input type="text" id="catdir" name="catdir" class="form-control required" minlength="1"/>
                        </div>
                    </div>
                    <?php endif;?>

                    <div class="form-group" id="module_url" style="display:none;">
                        <label class="control-label col-md-2">外部链接地址</label>
                        <div class="col-md-8">
                            <input type="text" name="url" class="form-control" value="<if condition="$vo['type']==2">{$vo['url']}</if>" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">栏目图片</label>
                        <div class="col-md-8">
                            <div class="thumb_image">
                                <div id="image_aid_box"></div>
                                <a class="thumbnail" href="javascript:swfupload('image','{:get_yzh_auth(1,'200kb',1)}',yesdo);">
                                    <img height="80" src="__IMG__/upload_thumb.png" id="image_pic" >
                                </a>
                                <input type="button" value="{:L('clean_thumb')}" onclick="javascript:clean_thumb('image');" class="btn btn-xs btn-primary"/>
                                <input type="hidden" id="image" name="image" value="{$vo['image']}"/>
                            </div>
                        </div>
                    </div>

                    <div class="form-group env-class" >
                        <label class="control-label col-md-2">导航</label>
                        <div class="col-md-8">
                            {:Form::radio(array('field'=>'ismenu','options'=>array('1'=>L('yes'),'0'=>L('no'))),1)}
                        </div>
                    </div>

                    <div class="form-group" <?php if($_SESSION['admin']['role'] != 1):?>style="display:none;"<?php endif;?>>
                        <label class="control-label col-md-2">分页条数</label>
                        <div class="col-md-8">
                            <input type="text" name="pagesize" class="form-control w-100" value="<if condition="!empty($vo['pagesize'])">{$vo['pagesize']}</if>"/> <font color="red">为空时默认值为系统设置的值</font>
                        </div>
                    </div>

                    <div class="form-group" <?php if($_SESSION['admin']['role'] != 1):?>style="display:none;"<?php endif;?>>
                        <label class="control-label col-md-2">列表页模板</label>
                        <div class="col-md-8">
                            <div class="selectstyle">
                                <select id="template_list" name="template_list" class="form-control pull-left w-300"></select>
                                &nbsp;&nbsp;
                                <input type="checkbox" class="input_checkbox pull-left" id="listtype" name="listtype" onclick="javascript:templatetype();" value="1" <if condition="!empty($vo['listtype'])">checked</if> />是否为封面栏目
                            </div>
                        </div>
                    </div>
                    <div class="form-group" <?php if($_SESSION['admin']['role'] != 1):?>style="display:none;"<?php endif;?>>
                        <label class="control-label col-md-2">内容页模板</label>
                        <div class="col-md-8">
                            <div class="selectstyle">
                                <select id="template_show" name="template_show" class="form-control w-300"></select>
                            </div>
                        </div>
                    </div>
                </div>

                <div role="tabpanel" class="tab-pane" id="profile">
                    <div class="form-group">
                        <label class="control-label col-md-2">SEO栏目标题</label>
                        <div class="col-md-8">
                            <input name='title' type='text' id='meta_title' value="{$vo['title']}" class="form-control"  size='60' maxlength='150'>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-2">SEO栏目关键词</label>
                        <div class="col-md-8">
                            <input name="keywords" type="text" class="form-control" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-2">SEO栏目简介</label>
                        <div class="col-md-8">
                            <textarea name="description" class="form-control" rows="5" cols="60"></textarea>
                        </div>
                    </div>
                </div>

                <!--<div role="tabpanel" class="tab-pane" id="extend">
                    <div class="form-group">
                        <label class="control-label col-md-2">英文标题</label>
                        <div class="col-md-8">
                            <input name="wap_catname" type="text" value="{$vo['wap_catname']}" class="form-control">
                        </div>
                    </div>
                </div>-->

            </div>
            <div class="form-actions">
                <button class="btn btn-primary submit ajax-post" type="submit">确定</button>
                <button class="btn btn-default return" onclick="javascript:history.back(-1);return false;">返回</button>
            </div>
        </form>

    </div>
</div>


</block>

<block name="script">
<script type="text/javascript">
$(document).ready(function() {
    $('#myform').ajaxForm({
        success:  complete,  // post-submit callback
        dataType: 'json'
    });
});
function complete(data){
    if(data.status==1){
        layer.msg(data.info, {
            icon: 1,
            time: 2000 //2秒关闭（如果不配置，默认是3秒）
        }, function(){
            window.location.href = "{$Think.cookie.__forward__}";
            return true;
        });
    }else{
        layer.msg(data.info, {
            icon: 2,
            time: 2000 //2秒关闭（如果不配置，默认是3秒）
        });
    }

}


$('.thumb_image a').click(function(){
    swfupload('image_uploadfile','image','{:L(uploadfiles)}',1,1,0,1,'jpeg,jpg,png,gif',300,0,'{$yzh_auth}',yesdo,nodo);
});


var modulearr = new Array();

<volist name="model" id="mdate">
modulearr[{$mdate['id']}] = "{$mdate['tablename']}";
</volist>

var templatearr = new Array();

<volist name="templates" id="tem">
templatearr[{$i}] = "{$tem['name']},{$tem['value']},{$tem['filename']}";
</volist>


var datas = "<option value=''>请选择</option>";
var modelid = $('#modelid').val();


showtemplist(modelid,<if condition="empty($vo[listtype])">0<else />{$vo.listtype}</if>);

function showtemplist(m,t){

    var type='_list';

    if(t){
        type='_index';
    }

    var mtlist = modulearr[m]+type;
    var mtshow = modulearr[m]+'_show';

    if(modulearr[m]=='Page')
        mtlist=mtshow ='Page_';

    $('#template_list').html(datas);
    $('#template_show').html(datas);

    listdatas = showdatas ='';

    for(i=1;i<templatearr.length;i++){
        data = templatearr[i].split(',');

        if(data[0].indexOf(mtlist)  >= 0){
            listdatas  ="<option value='"+data[1]+"'>"+data[2]+"</option>";
            $('#template_list').append(listdatas);
        }

        if(data[0].indexOf(mtshow)  >= 0){
            showdatas ="<option value='"+data[1]+"'>"+data[2]+"</option>";
            $('#template_show').append(showdatas);
        }
    }
    $("#template_list").attr("value",'{$vo.template_list}');
    $("#template_show").attr("value",'{$vo.template_show}');
}

function changetemplate(m){
    if(m==0){
        $('#module_url').show();
        $('#type').val('0');
        $('#catdir').removeClass('required');
    }else{
        $('#module_url').hide();
        $('#type').val('2');
        $('#catdir').addClass('required');
    }
    showtemplist(m,0);
    $("#listtype").removeAttr("checked");
}

function templatetype(){

    var moduleid = $('#moduleid').val();

    if($("#listtype").attr('checked')=='checked'){
        showtemplist(moduleid,1);
    }else{
        showtemplist(moduleid,0);
    }

}

function urlrule(m){
    if(m==1){
        $('#urlrule').show();
    }else{
        $('#urlrule').hide();
    }
}

urlrule({$vo['ishtml']});

<if condition="!empty($_GET['type'])">
    $('#modelid').val(0);
    changetemplate(0);
</if>
</script>
</block>